package com.mgfireworks.mgplatform.mgadmin.user;

import cn.hn.java.summer.annotation.ParamValid;
import com.mgfireworks.mgplatform.mgadmin.user.model.Role;
import com.mgfireworks.mgplatform.mgadmin.user.model.User;
import org.rythmengine.utils.F;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * 
 * @author nap
 * 20161015-10:19:48
 * 用户控制器
 */
@Controller
@RequestMapping("/user/user")
public class UserController {

	@Autowired
	UserService userService;
	@Autowired
	RoleService roleService;
	
	/**
	 * 用户列表
	 * @return
	 */
	@RequestMapping("/list")
	public F.T2<List<User>,List<Role>> list(User p){
		return F.T2(userService.getUsers(p),roleService.getAllRoles());
	}

	/**
	 * 添加用户
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public void add(User user){
	}
	
	/**
	 * 提交添加用户
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public void postAdd(@ParamValid User p){
		userService.addUser(p);
	}

	/**
	 * 编辑用户
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public User edit(User p){
		return userService.getUser(p);
	}
	
	/**
	 * 提交编辑用户
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	public void postEdit(@ParamValid User p){
		userService.editUser(p);
	}
	
	/**
	 * 获取用户
	 */
	@RequestMapping(value="/get",method=RequestMethod.GET)
	public User get(User p){
		return userService.getUser(p);
	}
	
	/**
	 * 删除用户
	 */
	@RequestMapping("/del")
	public void del(User p){
		userService.delUser(p);
	}
}